package cn.com.callback

import groovy.json.*;
import groovy.swing.impl.DefaultAction;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import cn.com.elite.EliteBean;
import java.security.MessageDigest;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.wisdge.dataservice.Result;
import java.util.Map;
import java.util.Date;
import java.util.HashMap;
import cn.com.elite.Util;
import java.net.URLEncoder;
import cn.com.kh.getProperty;


import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;

/**
 *
 * @Title: apiWorkGisStaff
 * @Description:布吉 GIS工单值班人员数据获取 中转--内部
 * @author: chieh
 * @date 2019-12-11 下午14:12:00
 *
 */


public class apiWorkGisStaff implements ServiceBackInvoke{
	private static final Log log = LogFactory.getLog(apiWorkGisStaff.class);
	public String doCallBack(EliteBean eliteBean,HttpServletRequest request,HttpServletResponse response) {

		response.setCharacterEncoding("UTF-8");

		String getMethod = request.getMethod();
		log.debug("getMethod:" + getMethod);

		String inData = "";
		String outData = "";
		String dataSourceID = "dataSource";

		BufferedReader iny = null;
		if (getMethod.equals("GET")) {
			inData = list.get(0).get("data");
			log.debug("原始Get请求参数:" + inData);
		} else {
			InputStreamReader reader = new InputStreamReader(request.getInputStream(), "UTF-8");
			iny = new BufferedReader(reader);
			String line;
			while ((line = iny.readLine()) != null) {
				inData += line;
			}
			log.debug("原始Post请求参数:" + inData);
		}

		try {
			// 调用处理信息
			JSONObject inObject = new JSONObject(inData);
			log.debug("处理前的Json：" + inObject.toString());

			String subunit = GetJV(inObject, "subunit");
			log.debug("解析信息- subunit：" + subunit);
			
			Map<String, String> headMap = new HashMap<String, String>();
			headMap.put("Content-Type", "text/html");
			
			//获取配置参数
			//String sysurl = "http://192.168.0.64:8080/SzbaDrainAgeManage/mobile/getUserToCustomService?subunit="+subunit;
			String sysurl = getProperty.get("YYGL.URL") +"/getUserToCustomService?subunit="+subunit;
			//String injson = "{\"subunit\":\"" + subunit + "\"}";
			log.debug("sysurl" + sysurl);
			
			outData=Util.doHttpPostUseHead(sysurl,"","UTF-8",10000,0,headMap);
			

		} catch (Exception e) {
			log.error("接口处理异常" + e.getMessage());
			// 失败返回
			outData = "{\"resultcode\":\"0\",\"resultmessage\":\"处理失败(" + e.getMessage() + "),调用问题处理时长(毫秒):2\",\"data\":[]}";

		}
		//log.debug("完成返回结果:" + outData);

		return outData;
	}

	// 解析Json值
	public static String GetJV(JSONObject inJson, String getKey) {
		String Rev_Value = null;
		try {
			Rev_Value = inJson.getString(getKey);
		} catch (Exception e) {
			try {
				Rev_Value = String.valueOf(inJson.getInt(getKey));
			} catch (Exception e1) {
				try {
					Rev_Value = String.valueOf(inJson.getJSONArray(getKey));
				} catch (Exception e2) {
					try {
						Rev_Value = String.valueOf(inJson.getJSONObject(getKey));
					} catch (Exception e3) {
						Rev_Value = "";
					}
				}
			}
		} finally {
			if (Rev_Value == null || Rev_Value.equals("null") || Rev_Value.length() <= 0) {
				Rev_Value = "";
			} else {
			}
		}
		return Rev_Value;
	}

}
